﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Data;
using System.Web.UI.WebControls;
using HZ.Supervise.IBLL;
using HZ.Supervise.Model;
using HZ.Supervise.Model.Query;

public partial class Company_NoSendDetail : BasePage
{

    DataTable dt;
    public string CompanyName_PS = "";
    public string CompanyID_PS = "";
    public Company_NoSendDetail()
    {

    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request.QueryString["CompanyID_PS"]))
        {
            CompanyID_PS = Server.UrlDecode(Request.QueryString["CompanyID_PS"].ToString());
        }
        if (!string.IsNullOrEmpty(Request.QueryString["CompanyName_PS"]))
        {
            CompanyName_PS = Server.UrlDecode(Request.QueryString["CompanyName_PS"].ToString());
        }
        if (!IsPostBack)
        {
            this.AreaControl1.InitAreaID = CurrentAccount.GetUser().Org.Area.AreaID;//初始化地区
            BindData();
        }
    }

 


    protected void BindData()
    {
        int TotalRecord;
        HZ.Supervise.IBLL.IBLL_ProcureCatalog ip = new HZ.Supervise.BLL.BLL_ProcureCatalog();
        UnDistributeCompanyQuery uq = (UnDistributeCompanyQuery)ViewState["UQuery"];
        UnDistributeCompanyQuery uqr = new UnDistributeCompanyQuery();
        if (!string.IsNullOrEmpty(txtCompanyName_SC.Text.Trim()))
        {
            uqr.CompanyName_SC = txtCompanyName_SC.Text.Trim();
        }
        if (!string.IsNullOrEmpty(txtOrderName.Text.Trim()))
        {
            uqr.OrderName = txtOrderName.Text.Trim();
        }
        if(!string.IsNullOrEmpty(txtHospitalName.Text.Trim()))
        {
            uqr.Append += "a.HospitalName LIKE '%" + txtHospitalName.Text.Trim() + "%' and ";
        }
        if (!string.IsNullOrEmpty(AreaControl1.SelectedAreaID) && AreaControl1.SelectedAreaID != "510000")
        {
            uqr.Append += "a.AreaID like '%" + AreaControl1.SelectedAreaID + "%' and";
        }

        uqr.Append += " a.CompanyID_PS = '" + CompanyID_PS + "' AND a.CompanyName_PS LIKE '%" + CompanyName_PS + "%'";

        if (!string.IsNullOrEmpty(txtBegin.Text.Trim()))
        {
            uqr.CenSubmiitTimeFrom = new HZ.Common.ConvertHelper(txtBegin.Text.Trim()).ToDateTime;
        }
        if (!string.IsNullOrEmpty(txtEnd.Text.ToString().Trim()))
        {
            uqr.CenSubmiitTimeTo = Convert.ToDateTime(txtEnd.Text.ToString().Trim()).AddDays(1);
        }
        uqr.SortFields = " CenSubmiitTime DESC";
        dt = ip.GetUnDistributeDetail( uqr, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out TotalRecord);

        AspNetPager1.RecordCount = TotalRecord;
        gvwInfo.DataSource = dt;
        gvwInfo.DataBind();

    }
    protected void btnQuery_Click(object sender, EventArgs e)
    {
        AspNetPager1.CurrentPageIndex = 1;
    }
    protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
    {
        BindData();
    }
    /// <summary>
    /// 导出    by张雄
    /// </summary>
    /// <param name="sender">事件发送源</param>
    /// <param name="e">事件参数</param>
    protected void btnExcel_Click(object sender, EventArgs e)
    {
        int TotalRecord;
        HZ.Supervise.IBLL.IBLL_ProcureCatalog ip = new HZ.Supervise.BLL.BLL_ProcureCatalog();
        UnDistributeCompanyQuery uq = (UnDistributeCompanyQuery)ViewState["UQuery"];
        UnDistributeCompanyQuery uqr = new UnDistributeCompanyQuery();
        if (!string.IsNullOrEmpty(txtCompanyName_SC.Text.Trim()))
        {
            uqr.CompanyName_SC = txtCompanyName_SC.Text.Trim();
        }
        if (!string.IsNullOrEmpty(txtOrderName.Text.Trim()))
        {
            uqr.OrderName = txtOrderName.Text.Trim();
        }
        if (!string.IsNullOrEmpty(txtHospitalName.Text.Trim()))
        {
            uqr.Append += "a.HospitalName LIKE '%" + txtHospitalName.Text.Trim() + "%' and ";
        }
        if (!string.IsNullOrEmpty(AreaControl1.SelectedAreaID) && AreaControl1.SelectedAreaID != "510000")
        {
            uqr.Append += "a.AreaID like '%" + AreaControl1.SelectedAreaID + "%' and";
        }

        uqr.Append += " a.CompanyID_PS = '" + CompanyID_PS + "' AND a.CompanyName_PS LIKE '%" + CompanyName_PS + "%'";

        if (!string.IsNullOrEmpty(txtBegin.Text.Trim()))
        {
            uqr.CenSubmiitTimeFrom = new HZ.Common.ConvertHelper(txtBegin.Text.Trim()).ToDateTime;
        }
        if (!string.IsNullOrEmpty(txtEnd.Text.ToString().Trim()))
        {
            uqr.CenSubmiitTimeTo = Convert.ToDateTime(txtEnd.Text.ToString().Trim()).AddDays(1);
        }
        uqr.SortFields = " CenSubmiitTime DESC";
        dt = ip.GetUnDistributeDetail(uqr, 0, 0, out TotalRecord);

        ExportFile.Instance.ExportData(dt, gvwInfo, this.Page);

    }

    /// <summary>
    /// 前台的时间格式到后台判断
    /// 2011.4.13 张雄 modify 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gvwInfo_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lbl1 = e.Row.FindControl("Label1") as Label;

            DataRowView dr = e.Row.DataItem as DataRowView;

            string CenSubmiitTime = dr["CenSubmiitTime"].ToString();
            string CompanyValidateWarehouseTime = dr["CompanyValidateWarehouseTime2daysago"].ToString();
            if (!string.IsNullOrEmpty(CenSubmiitTime))
	        {
                if (string.IsNullOrEmpty(CompanyValidateWarehouseTime))
                {
                    lbl1.Text = (DateTime.Now.AddDays(-2) - Convert.ToDateTime(CenSubmiitTime)).Days.ToString();
                }
                else if (!string.IsNullOrEmpty(CompanyValidateWarehouseTime))
                {
                    lbl1.Text = (Convert.ToDateTime(CompanyValidateWarehouseTime) - Convert.ToDateTime(CenSubmiitTime)).Days.ToString();
                }
	        }
        }
    }
}
